# This is the makefile

CC = mpicc
BIN = raytrace
FLAGS = -Wall -Wextra -g

INCLUDE = include /usr/include/libpng12
INCLUDE := $(addprefix -I, $(INCLUDE))

LIBS = m png12
LIBS := $(addprefix -l, $(LIBS))

SRC = src/slave_process.c \
      src/master_process.c \
      src/main.c \
      src/mpi_partitionings.c \
      src/task_list.c
OBJS = $(subst src/, objs/, $(SRC:.c=.o))

all: $(BIN)

$(BIN) : $(OBJS)
	if [ x"`uname -a | grep phoenix`" != "x" ] ; then \
		$(CC) -o $(BIN) $(OBJS) $(FLAGS) $(INCLUDE) $(LIBS) -Lobjs/phoenix -lraytrace;\
	elif [ x"`uname -a | grep node-`" != "x" ] ; then \
		$(CC) -o $(BIN) $(OBJS) $(FLAGS) $(INCLUDE) $(LIBS) -Lobjs/phoenix -lraytrace;\
	elif [ x"`uname -a | grep i686`" != "x" ] ; then \
		$(CC) -o $(BIN) $(OBJS) $(FLAGS) $(INCLUDE) $(LIBS) -Lobjs/i686 -lraytrace;\
	elif [ x"`uname -a | grep x86_64`" != "x" ] ; then \
		$(CC) -o $(BIN) $(OBJS) $(FLAGS) $(INCLUDE) $(LIBS) -Lobjs/x86 -lraytrace;\
	elif [ x"`uname -a | grep i386`" != "x" ] ; then \
		$(CC) -o $(BIN) $(OBJS) $(FLAGS) $(INCLUDE) $(LIBS) -Lobjs/i386 -lraytrace;\
	else \
		@echo "Provided code will not compile on this system.";\
	fi

objs/%.o: src/%.c
	$(CC) -c -o $@ $< $(FLAGS) $(INCLUDE)

clean:
	rm -f objs/*.o
	rm -f $(BIN)
